package com.yq.homework.day24;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author 3307235355@qq.com
 * @since 2022/06/24 19:25
 * 读取一个文件，这个文件中有随机的一些数字字符，统
 * 计这些数字有几个偶数，几个奇数，并且追加写入到该文件末尾。
 * 例如：a.txt文件内容为
 * 3241256364789629090126581212515
 * 奇数：xx个
 * 偶数：xx个
 */
public class Demo02 {
    public static void main(String[] args) throws IOException {
        FileInputStream in = new FileInputStream("a.txt");
        FileOutputStream out = new FileOutputStream("a.txt",true);
        int readDate;
        int count = 0;
        int count1 = 0;
        while ((readDate = in.read()) != -1) {
            char readDate1 = (char) readDate;
            if (((int) readDate1) % 2 == 0) {
                count++;
            }else {
                count1++;
            }
        }
        String o = "偶数："+count;
        String j = "奇数："+count1;

        out.write(System.lineSeparator().getBytes());
        out.write(o.getBytes());
        out.write(j.getBytes());


        in.close();
        out.close();

    }
}
